//
//  ViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/2/17.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    let screenSize = UIScreen.main.bounds.size;
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.white;
        
        self.onCreateUIForView();
    }

    func onCreateUIForView() {
        let scrollView:UIScrollView = UIScrollView.init(frame: CGRect.init(x: 0, y: 0, width: screenSize.width, height: screenSize.height));
        scrollView.backgroundColor = UIColor.lightGray;
        scrollView.showsVerticalScrollIndicator = false;
        scrollView.showsHorizontalScrollIndicator = false;
        self.view.addSubview(scrollView);
        
        let _titleArray = ["导航栏透明","MapKit使用","图片轮播","表联动","cell展开","AVKit使用x","动画","tabbar使用","网页WK","手势放大","UICollection","下拉背景放大","相册选择器","本地推送x","拓展","UITableView","搜索栏使用x","防微博界面x","字体列表"];
        let itemLeft:CGFloat = 15;
        let itemWidth = (screenSize.width - itemLeft*4)/3;
        var itemTop:CGFloat = 60;
        let itemHeight:CGFloat = 40;
        for index in 0..._titleArray.count-1 {
            let title = _titleArray[index];
            itemTop = 60 + CGFloat(index/3)*(itemHeight+20);
//            print("展示：\(title)");
            
            let bt = UIButton.init(type: .custom);
            bt.frame = CGRect.init(x: itemLeft+(itemWidth+itemLeft)*CGFloat(index % 3), y: itemTop, width: itemWidth, height: itemHeight);
            bt.setTitle(title, for: .normal);
            bt.addTarget(self, action: #selector(onClickAction(bt:)), for: .touchUpInside);
            bt.tag = 1000 + index;
            bt.layer.cornerRadius = 5;
            bt.layer.borderWidth = 1;
            bt.layer.borderColor = UIColor.white.cgColor;
            bt.layer.masksToBounds = true;
            scrollView.addSubview(bt);
            
        }
        
        if scrollView.frame.size.height >= itemTop {
            scrollView.contentSize = CGSize(width: 0, height: scrollView.frame.size.height);
        } else {
            scrollView.contentSize = CGSize(width: 0, height: itemTop);
        }
    }
    
    @objc func onClickAction(bt:UIButton) {
        print("按钮tag:\(bt.tag)");
        //每条后系统自动添加break
        switch bt.tag-1000 {
        case 0:
            let firstVC = FirstViewController();
            let firstNav = UINavigationController(rootViewController: firstVC);
            firstNav.modalPresentationStyle = .fullScreen;
            self.present(firstNav, animated: true, completion: nil);
//            fallthrough;//执行完本条，自动执行下一条
        case 1:
            let secondVC = SecondViewController();
            let secondNav = UINavigationController(rootViewController: secondVC);
            secondNav.modalPresentationStyle = .fullScreen;
            self.present(secondNav, animated: true, completion: nil);
        case 2:
            let threeVC = ThreeViewController();
            let threeNav = UINavigationController(rootViewController: threeVC);
            threeNav.modalPresentationStyle = .fullScreen;
            self.present(threeNav, animated: true, completion: nil);
        case 3:
            let fourVC = FourViewController();
            let fourNav = UINavigationController(rootViewController: fourVC);
            fourNav.modalPresentationStyle = .fullScreen;
            self.present(fourNav, animated: true, completion: nil);
        case 4:
            let fiveVC = FiveViewController();
            let fiveNav = UINavigationController(rootViewController: fiveVC);
            fiveNav.modalPresentationStyle = .fullScreen;
            self.present(fiveNav, animated: true, completion: nil);
        case 6:
            let sevenVC = SevenViewController();
            let sevenNav = UINavigationController(rootViewController: sevenVC);
            sevenNav.modalPresentationStyle = .fullScreen;
            self.present(sevenNav, animated: true, completion: nil);
        case 7:
            let eightVC = EightViewController();
            let eightNav = UINavigationController(rootViewController: eightVC);
            eightNav.modalPresentationStyle = .fullScreen;
            self.present(eightNav, animated: true, completion: nil);
        case 8:
            let nineVC = NineViewController();
            let nineNav = UINavigationController(rootViewController: nineVC);
            nineNav.modalPresentationStyle = .fullScreen;
            self.present(nineNav, animated: true, completion: nil);
        case 9:
            let tenVc = TenViewController();
            let tenNav = UINavigationController(rootViewController: tenVc);
            tenNav.modalPresentationStyle = .fullScreen;
            self.present(tenNav, animated: true, completion: nil);
        case 10:
            let elevenVc = ElevenViewController();
            let elevenNav = UINavigationController(rootViewController: elevenVc);
            elevenNav.modalPresentationStyle = .fullScreen;
            self.present(elevenNav, animated: true, completion: nil);
        case 11:
            let twelveVC = TwelveViewController();
            let twelveNav = UINavigationController(rootViewController: twelveVC);
            twelveNav.modalPresentationStyle = .fullScreen;
            self.present(twelveNav, animated: true, completion: nil);
        case 12:
            let thirteenVC = ThirteenViewController();
            let thirteenNav = UINavigationController(rootViewController: thirteenVC);
            thirteenNav.modalPresentationStyle = .fullScreen;
            self.present(thirteenNav, animated: true, completion: nil);
        case 14:
            let fifteenVC = FifteenViewController();
            let fifteenNav = UINavigationController(rootViewController: fifteenVC);
            fifteenNav.modalPresentationStyle = .fullScreen;
            self.present(fifteenNav, animated: true, completion: nil);
        case 15:
            let sixteenVC = SixteenViewController();
            let sixteenNav = UINavigationController(rootViewController: sixteenVC);
            sixteenNav.modalPresentationStyle = .fullScreen;
            self.present(sixteenNav, animated: true, completion: nil);
        case 16:
            let seventeenVC = SeventeenViewController();
            let seventeenNav = UINavigationController(rootViewController: seventeenVC);
            seventeenNav.modalPresentationStyle = .fullScreen;
            self.present(seventeenNav, animated: true, completion: nil);
        default:
            ""
        }
    }
}

